package ch2.sq;

public class SqListExam {
    public static void main(String[] args) {
        //测试1
        System.out.println("*******测试1****************");
        Integer[] a = {1, 2, 3, 4, 5};
        SqListClass<Integer> L1 = new SqListClass<>();
        L1.CreateList(a);
        System.out.println("L1: " + L1);
        System.out.println("L1长度=" + L1.size());

        L1.Add(10);
        System.out.println("L1: " + L1.toString());
        System.out.println("求每个序号的元素值");
        for (int i = 0; i < L1.size(); i++) {
            System.out.println("  序号" + i + "的元素值:" + L1.GetElem(i));
        }

        System.out.println("重新置长度为5");
        L1.Setsize(5);
        System.out.println("L1: " + L1.toString());

        int i = 1;
        int x = 20;  // 装箱：int -> Integer, 拆箱：Integer -> int
        System.out.println("在序号" + i + "位置插入" + x);
        L1.SetElem(i, x);
        System.out.println("L1: " + L1.toString());

        i = 3;
        System.out.println("删除序号" + i + "的元素");
        L1.Delete(i);
        System.out.println("L1: " + L1.toString());

        i = 2;
        x = 16;
        System.out.println("设置序号" + i + "的元素值为" + x);
        L1.SetElem(i, x);
        System.out.println("L1: " + L1.toString());

        x = 5;
        System.out.println("值为" + x + "的元素序号为" + L1.GetNo(x));

        //测试2
        System.out.println();
        System.out.println("*******测试2****************");
        Character[] b = {'a', 'b', 'c', 'd', 'e', 'f'};
        SqListClass<Character> L2 = new SqListClass<>();
        L2.CreateList(b);
        System.out.println("L2: " + L2.toString());
        System.out.println("L2长度=" + L2.size());

        L2.Add('x');
        System.out.println("L2: " + L2.toString());
        System.out.println("求每个序号的元素值");
        for (i = 0; i < L2.size(); i++) {
            System.out.println("  序号" + i + "的元素值:" + L2.GetElem(i));
        }

        System.out.println("重新置长度为5");
        L2.Setsize(5);
        System.out.println("L2: " + L2.toString());

        i = 1;
        Character y = 'y';
        System.out.println("在序号" + i + "位置插入" + y);
        L2.SetElem(i, y);
        System.out.println("L2: " + L2.toString());

        i = 3;
        System.out.println("删除序号" + i + "的元素");
        L2.Delete(i);
        System.out.println("L2: " + L2.toString());

        i = 2;
        y = 'z';
        System.out.println("设置序号" + i + "的元素值为" + y);
        L2.SetElem(i, y);
        System.out.println("L2: " + L2.toString());

        y = 'd';
        System.out.println("值为" + y + "的元素序号为" + L2.GetNo(y));
    }
}

